package logic

import (
	"context"
	"srv/models/mysql"

	"srv/internal/svc"
	"srv/sesame"

	"github.com/zeromicro/go-zero/core/logx"
)

type OrderListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewOrderListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OrderListLogic {
	return &OrderListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *OrderListLogic) OrderList(in *sesame.OrderListRequest) (*sesame.OrderListResponse, error) {
	// todo: add your logic here and delete this line
	o := mysql.Order{}
	list, err := o.OrderList(int64(o.OrderStatus))
	if err != nil {
		return nil, err
	}
	var OrderList []*sesame.OrderInfo
	for _, order := range list {
		OrderList = append(OrderList, &sesame.OrderInfo{
			UserId:      int64(order.UserId),
			OrderSn:     order.OrderSn,
			Num:         int64(order.Num),
			Amount:      float32(order.Amount),
			OrderType:   int64(order.OrderType),
			OrderStatus: int64(order.OrderStatus),
			Time:        order.Time,
			GoodsTitle:  order.GoodsTitle,
			GoodsStock:  int64(order.GoodsStock),
			GoodsPrice:  float32(order.GoodsPrice),
		})
	}
	return &sesame.OrderListResponse{
		List: OrderList,
	}, nil
}
